package indi.zhifa.study2024.class002.busy.generalTest.business.report.consign.entity.request;

import indi.zhifa.study2024.class002.busy.generalTest.business.report.consign.entity.mapperIn.ConsignMapperIn;
import indi.zhifa.study2024.class002.busy.generalTest.enums.bill.consign.EConsignReportOrderType;
import indi.zhifa.study2024.class002.busy.generalTest.enums.common.EOrderType;
import indi.zhifa.study2024.core.common.web.entity.request.BasePageRequest;
import lombok.Data;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

@Data
public abstract class BaseConsignReportRequest extends BasePageRequest {
    Long itemId;
    String itemName;
    String mainType;
    String segmentType;
    String brand;
    Long customerId;
    String customerName;
    Long salesId;
    String salesName;
    LocalDateTime timeBegin;
    LocalDateTime timeEnd;
    EConsignReportOrderType consignOrderType;
    EOrderType orderType;

    public BaseConsignReportRequest(){
        timeBegin = LocalDateTime.now().minusDays(3l);
        timeEnd = LocalDateTime.now();
        consignOrderType = EConsignReportOrderType.BILL_TIME;
        orderType = EOrderType.DESC;
    }

    public  ConsignMapperIn toMapperIn(){
        ConsignMapperIn consignMapperIn = new ConsignMapperIn();
        consignMapperIn.setItemId(itemId);
        consignMapperIn.setItemName(itemName);
        consignMapperIn.setMainType(mainType);
        consignMapperIn.setSegmentType(segmentType);
        consignMapperIn.setBrand(brand);
        consignMapperIn.setCustomerId(customerId);
        consignMapperIn.setCustomerName(customerName);
        consignMapperIn.setSalesId(salesId);
        consignMapperIn.setSalesName(salesName);
        consignMapperIn.setConsignOrderType(consignOrderType);
        consignMapperIn.setOrderType(orderType);

        Instant instantBeg = timeBegin.toInstant(ZoneOffset.UTC);
        consignMapperIn.setBillTimeBegin(instantBeg.getEpochSecond());
        Instant instantEnd = timeEnd.toInstant(ZoneOffset.UTC);
        consignMapperIn.setBillTimeEnd(instantEnd.getEpochSecond());

        if(size > 0){
            consignMapperIn.setPage(true);
            consignMapperIn.setOffset((current-1)*size);
            consignMapperIn.setLimit(size);
        }else{
            consignMapperIn.setPage(false);
        }

        consignMapperIn = onConsignMapperInInit(consignMapperIn);
        return consignMapperIn;

    }

    protected abstract ConsignMapperIn onConsignMapperInInit(ConsignMapperIn pConsignMapperIn);

}
